import React, { Component } from 'react';
import { NavBar } from 'antd-mobile';
// import { good_favlist,good_unfav } from '../utils/api'
import{request_cancel_collect } from '../store/actionCreator'
import { connect } from 'react-redux'
class Collection extends Component {

    constructor(props) {
        super(props);
        this.back = this.back.bind(this);
        this.state = {
            favlist: [],
            
        }
    }
    back() {
        this.props.history.go(-1)
    }
    
    render() {
        console.log(this.props.collectlist[0]);
        
        return (
            <div className='collection'>
                <div>
                    <NavBar back='返回' onBack={this.back} left=''>
                        我的收藏
                    </NavBar>
                </div>
                <div className='collectionlist'>{
                    this.props.collectlist.map((item, index) => {
                        return (
                            <div className='collectionlist_1' key={index}>
                                <div className='collectionlist_img'>
                                    <img src={item.pic} alt="" />
                                </div>
                                <div className='collectionlist_img_right'>
                                    <div className='name'>{item.name}</div>
                                    <p>原价{item.salesPrice.value}</p>
                                    <div className='name_bottom'>
                                        <div>活动价 <span>215</span> </div>
                                        <div className='name_bottom_1' onClick={()=>{this.props.cancel_collect(item)}}>取消收藏</div>
                                    </div>
                                </div> 

                            </div>
                        )
                    })
                }

                </div>

            </div>
        );
    }
}

export default connect(
    (state)=>{//负责注入数据到props
        return {
            "collectlist":state.collectlist
        }
    },
    (dispatch)=>{//负责注入方法到组件props
        return {
            cancel_collect(params){
                dispatch( request_cancel_collect(params) );
            }
        }
    }
)(Collection);